from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import unittest


class douban(unittest.TestCase):

    def setUp(self) -> None:
        # 打开浏览器
        self.driver = webdriver.Chrome()
        self.driver.get('https://www.douban.com/')
        time.sleep(2)
        # 窗口最大化
        self.driver.maximize_window()
        self.driver.implicitly_wait(5)

    def tearDown(self) -> None:
        time.sleep(5)
        self.driver.quit()

    def test_qq_douban_01(self):
        # 进入frame框架
        f = self.driver.find_element(By.XPATH, '/html/body/div[2]/div/div[1]/iframe')
        self.driver.switch_to.frame(f)
        # 第一步：输入手机号
        self.driver.find_element(By.CLASS_NAME, 'account-form-input').send_keys('15985645480')
        # 强制等待30秒  输入验证码
        time.sleep(30)
        # 第二步：点击登录豆瓣
        self.driver.find_element(By.XPATH, '/html/body/div[1]/div[2]/div[1]/div[5]/a').click()
        time.sleep(3)
        # 退出frame框架
        self.driver.switch_to.default_content()
        time.sleep(2)
        # # 断言1：验证登录成功后断言 ：小高先生的账号
        dy1 = self.driver.find_element(By.XPATH, '/html/body/div[1]/div/div[1]/ul/li[2]/a/span[1]').text
        self.assertEqual('小高先生的账号', dy1)



if __name__ == '__main__':
    unittest.main()

